package com.wgy.blog.controller;

import com.sun.org.glassfish.external.probe.provider.annotations.ProbeParam;
import com.wgy.blog.common.Result;
import com.wgy.blog.pojo.Login;
import com.wgy.blog.pojo.User;
import com.wgy.blog.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author:Iny
 * @Data：2021/11/5 14:01
 */

@RestController
@RequestMapping
public class LoginController {

    @Resource
    UserService userService;

    @PostMapping("login")
    public Result login(@RequestBody Login login){
        String token = userService.login(login);
        if (token!=null)
        {
            return Result.success(1,token);
        }
       return Result.fail();

    }
    @GetMapping("info")
    public Result loginInfo(String token){
//        User userByName = userService.getUserByName(token);
        Map<String,Object> map = new HashMap<>();
        map.put("roles","超级管理员");
        map.put("name","admin");
//        头像
        map.put("avatar","http://localhost:8082/avatar/16348666662397153.jpg");
        return Result.success(map);
    }

    @PostMapping("logout")
    public Result logout(String token){
        return Result.success();
    }
}
